/*
 * uart.h
 *
 *  Created on: Jun 10, 2024
 *      Author: PIANO
 */

#ifndef INC_UART_H_
#define INC_UART_H_

/**
 * includes
 *
 */
#include "app.h"

/**
 * defines
 *
 */
#define BUFFER_SIZE			256
#define MAX_TIME_OUT		600000
#define MAX_INTERVAL		600000
#define IOT_PWR(PinState)	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, PinState)

/**
 * typedefs
 *
 */
typedef enum {
	UART_IDLE = 0,
	UART_START = 100,
	UART_BUILD,
	UART_SEND,
	UART_RECEIVE,
	UART_RETRY,
	UART_OK = 200,
	UART_PROTOCOL_ERR = 300,
	UART_PARAMETER_ERR,
	UART_ERROR = 400,
	UART_TIMEOUT,
	UART_ACKERROR
} UART_StatusTypeDef;

typedef struct {

	uint16_t status;
	uint32_t timeOut;
	uint16_t timeOutSet;
	uint16_t retryTimes;
	uint16_t retryTimesSet;
	uint32_t interval;
	uint16_t intervalSet;

	uint8_t txBuffer[256];
	uint8_t rxBuffer[256];
	uint16_t txCount;
	uint16_t rxCount;

} UART_DataTypeDef;

/**
 * functions
 *
 */
void uartSetup(void);
void uartLoop(void);
void uartTask1ms(void);
void uartSend(UART_HandleTypeDef *huart, UART_DataTypeDef *duart);
void uartIsr(UART_HandleTypeDef *huart);

#endif /* __UART_H_ */
